//
//@File    :	14.23_tmp2temp.cpp
//@Time    :	2022/02/24 14:08:01
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	template friends to a template class
//

#include <iostream>
using std::cout;
using std::endl;
//template prototypes
template<typename T>void counts();
template<typename T>void report(T &);

//template class
template <typename TT>
class HasFriendT
{
private:
    TT item;
    static int ct;

public:
    HasFriendT(const TT & i):item(i){ct++;}
    ~HasFriendT(){ct--;}
    friend void counts<TT>();
    friend void report<>(HasFriendT<TT> &);
};

template<typename T>
int HasFriendT<T>::ct=0;

template<typename T>
void counts()
{
    cout<<"template size: "<<sizeof(HasFriendT<TT>)<<"; ";
    cout<<"template counts(): "<<HasFriendT<T>::ct<<endl;
}

template<typename T>
void report(T &hf){
    cout<<hf.item<<endl;
}


int main()
{
    counts<int>();
    HasFriendT<int> hfi1(10);
    HasFriendT<int> hfi2(20);
    HasFriendT<double> hfdb(10.5);
    report(hfi1);
    report(hfi2);
    report(hfdb);

    cout<<"counts<int>() output:\n";
    counts<int>();
    cout<<"counts<double>() output:\n";
    counts<double>();
//counts<int>与counts<double>输出的模板大小不同
//表明每种T类型都有自己的友元函数count();
    system("pause");
    return 0;
}